home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7056 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  44 lines

  1. Path: newsbf02.news.aol.com!not-for-mail
  2. From: asciizero@aol.com (ASCII zero)
  3. Newsgroups: comp.lang.c
  4. Subject: I can't print the date in the format I want.
  5. Date: 17 Feb 1996 18:11:43 -0500
  6. Organization: America Online, Inc. (1-800-827-6364)
  7. Sender: root@newsbf02.news.aol.com
  8. Message-ID: <4g5nbf$8s0@newsbf02.news.aol.com>
  9. Reply-To: asciizero@aol.com (ASCII zero)
  10. NNTP-Posting-Host: newsbf02.mail.aol.com
  11.  
  12. Hi!  It is I once again.
  13.  
  14. I am trying to use strftime() to format the date into YY-MM-DD. The format
  15. seems to be working but I am unable to actually print the formatted
  16. string. It compiles just fine using gcc. What have I overlooked?
  17.  
  18. #include <stdio.h>
  19. #include <time.h>
  20.  
  21. main()
  22. {
  23.  
  24.  struct tm *ptr;
  25.  time_t lt;
  26.  char *str;
  27.  int debug;  /* inserted for debugging purposes */
  28.  
  29.  lt = time(NULL);
  30.  ptr = localtime(<);
  31.  printf("\n The system clock shows: %s\n\n", asctime(ptr));
  32.  debug = strftime(str, 50, "The current date is %y-%m-%d", ptr);
  33.  printf("-> %i", debug);          /* can we get the length of the
  34. formatted string? */
  35.  getchar();                           /* OK up to this point? */
  36.  printf("%s", str);
  37.  
  38. }
  39.  
  40.  
  41. Please help. Thanks.   -jj
  42.  
  43. asciizero@aol.com(J.J. Cariaso)
  44.